package csm.api.search.impl;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import csm.api.search.ISearchResult;
import csm.common.net.HttpRequester;

public final class NaverSearchProvider extends SearchProviderBase
{
    @Override
    public ISearchResult search() throws Exception
    {
        ISearchResult result = null;
        StringBuffer sb = new StringBuffer();
        try
        {
            // http://openapi.naver.com/search?key=test&query=%EC%A3%BC%EC%8B%9D&target=news&start=1&display=10
            sb.append("http://openapi.naver.com/search?");
            sb.append("key=").append(this.getRequest().getApiKey());
            sb.append("&query=").append(URLEncoder.encode(this.getRequest().getSearchData(), "UTF-8"));
            sb.append("&target=").append(this.getRequest().getDefaultUrlParam());
            sb.append("&start=").append(this.getRequest().getCurrentPage());
            sb.append("&display=").append(this.getRequest().getPageSize());
            sb.append("&sort=").append("sim");

            HttpRequester worker = new HttpRequester();


            String returnXml = worker.executeString(sb.toString());
            result = new SearchResultBase();
            result.setRawString(returnXml);

        }
        catch (UnsupportedEncodingException e)
        {
        }

        return result;
    }

}
